# Contributor: Clayton Craft <clayton@craftyguy.net>
# Contributor: Thomas Böhler <witcher@wiredspace.de>
# Maintainer: Clayton Craft <clayton@craftyguy.net>
pkgname=goimapnotify
pkgver=2.3.12
pkgrel=1
pkgdesc="execute scripts on IMAP mailbox changes using IDLE, golang version"
url="https://gitlab.com/shackra/goimapnotify"
arch="all"
license="GPL-3.0-or-later"
makedepends="go"
options="net"
source="https://gitlab.com/shackra/goimapnotify/-/archive/$pkgver/goimapnotify-$pkgver.tar.gz"

export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare
	go get -u golang.org/x/sys@v0.6.0
	go get -u golang.org/x/net@v0.6.0
	go mod tidy
}

build() {
	export CGO_CPPFLAGS="$CPPFLAGS"
	export CGO_CFLAGS="$CFLAGS"
	export CGO_CXXFLAGS="$CXXFLAGS"
	export CGO_LDFLAGS="$LDFLAGS"
	export GOFLAGS="$GOFLAGS -trimpath -mod=readonly -modcacherw"

	go build -ldflags "-linkmode=external \"-extldflags=$LDFLAGS\""
}

check() {
	go test ./...
}

package() {
	install -Dm755 goimapnotify "$pkgdir"/usr/bin/goimapnotify
	install -Dm644 LICENSE "$pkgdir"/usr/share/licenses/"$pkgname"/LICENSE
	install -Dm644 README.md "$pkgdir"/usr/share/doc/"$pkgname"/README.md
	install -Dm644 CHANGELOG.rst "$pkgdir"/usr/share/doc/"$pkgname"/CHANGELOG.rst
}

sha512sums="
c3061af4df07dc2e58b338b25a933b9bd31693e2a8a50fe7f6dcc921f8ee48975d97d9c3f9bea1804f3f6e2a0f282984d72152e7cc3e57a8485300369819461f  goimapnotify-2.3.12.tar.gz
"
